// VBConversions Note: VB project level imports
using System.Collections.Generic;
using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using Microsoft.VisualBasic.Compatibility;
using System.Windows.Forms;
using System.Collections;
using System.Data;
// End of VB project level imports

using System.Drawing.Drawing2D;

namespace 喷码数据生成工具
{
	public partial class frm_SettingList
	{
		bool ButtonMode = false;
		Color mBorderColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color mBackColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ItemSelectColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ItemSelectColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ItemSelectForeColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ItemForeColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumbNormalBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors. // Color.FromArgb(230, 230, 230)
		Color ThumBNormalColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBNormalColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBNormalColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBNormalColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBNormalColor5; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumbHoverBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBHoverColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBHoverColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBHoverColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBHoverColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBHoverColor5; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumbDownBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBDownColor1; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBDownColor2; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBDownColor3; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBDownColor4; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumBDownColor5; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color ThumbBorder; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		Color thumbBackColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		int MouseX;
		int MouseY;
		bool DownEvent = false;
		bool ButtonDownEvent = false;
		bool OverB = false;
		int ScrollWidth = 11;
		int MaxValue;
		float Value;
		int mFirstIndex = 0;
		const int ItemHeight = 25;
		const int EffectHeight = 5;
		const int MinHeight = 30;
		int DisplayHeight;
		Bitmap DisplayImage;
		public struct ItemStructure
		{
			public string Text;
			public object Tag;
		}
		List<ItemStructure> sItem = new List<ItemStructure>();
		int mSelectedIndex = 5;
		Form frmSource;
#region 构造函数
		public frm_SettingList(Form1 ParentForm)
		{
			// VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
			mBorderColor = Color.FromArgb(230, 0, 147, 209);
			mBackColor = Color.FromArgb(200, 255, 255, 255);
			ItemSelectColor1 = Color.FromArgb(62, 150, 215);
			ItemSelectColor2 = Color.FromArgb(51, 138, 202);
			ItemSelectForeColor = Color.White;
			ItemForeColor = Color.Blue;
			ThumbNormalBorder = Color.Black;
			ThumBNormalColor1 = Color.FromArgb(246, 244, 239);
			ThumBNormalColor2 = Color.FromArgb(238, 234, 227);
			ThumBNormalColor3 = Color.FromArgb(228, 224, 213);
			ThumBNormalColor4 = Color.FromArgb(216, 213, 198);
			ThumBNormalColor5 = Color.FromArgb(246, 244, 239);
			ThumbHoverBorder = Color.FromArgb(180, 180, 180);
			ThumBHoverColor1 = Color.FromArgb(236, 234, 229);
			ThumBHoverColor2 = Color.FromArgb(228, 224, 217);
			ThumBHoverColor3 = Color.FromArgb(218, 214, 203);
			ThumBHoverColor4 = Color.FromArgb(206, 203, 188);
			ThumBHoverColor5 = Color.FromArgb(236, 234, 229);
			ThumbDownBorder = Color.FromArgb(140, 140, 140);
			ThumBDownColor1 = Color.FromArgb(206, 204, 199);
			ThumBDownColor2 = Color.FromArgb(188, 184, 177);
			ThumBDownColor3 = Color.FromArgb(178, 174, 163);
			ThumBDownColor4 = Color.FromArgb(166, 163, 148);
			ThumBDownColor5 = Color.FromArgb(196, 194, 189);
			ThumbBorder = Color.FromArgb(100, 100, 100);
			thumbBackColor = Color.FromArgb(160, 160, 160);
			
			
			// 此调用是 Windows 窗体设计器所必需的。
			InitializeComponent();
			
			// 在 InitializeComponent() 调用之后添加任何初始化。
			ButtonMode = true;
			frmSource = ParentForm;
		}
#endregion
public List<ItemStructure> Items
		{
			get
			{
				return sItem;
			}
		}
		public void AddItem(string Text, object mTag)
		{
			ItemStructure tmpItem = new ItemStructure();
			tmpItem.Text = Text;
			tmpItem.Tag = mTag;
			sItem.Add(tmpItem);
			int PageCount = 0;
			PageCount = (int) ((double) (this.Height - 1 - EffectHeight * 2) / ItemHeight);
			if (sItem.Count > PageCount)
			{
				ThumbButton.Visible = true;
			}
			else
			{
				ThumbButton.Visible = false;
			}
			MaxValue = sItem.Count - PageCount;
			CaculateThumbHeight();
			if (sItem.Count - mFirstIndex <= PageCount)
			{
				sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
			}
		}
		
		public void frm_SettingList_Activated(object sender, System.EventArgs e)
		{
		}
		public void frm_SettingList_Deactivate(object sender, System.EventArgs e)
		{
			this.Hide();
		}
		public void frm_SettingList_DoubleClick(object sender, System.EventArgs e)
		{
			if (mSelectedIndex >= 0 & mSelectedIndex < sItem.Count)
			{
				((Form1) frmSource).HandleMenuListClick(sItem[mSelectedIndex].Tag);
			}
			this.Hide();
		}
		
		public void frm_SettingList_Load(System.Object sender, System.EventArgs e)
		{
			// Me.BackColor = Color.ForestGreen
			//DrawFormButtonMode(ENUMMOUSEEVENT.MOUSENORMAL)
			int PageCount = 0;
			PageCount = (int) ((double) (this.Height - 1 - EffectHeight * 2) / ItemHeight);
			if (sItem.Count > PageCount)
			{
				ThumbButton.Visible = true;
			}
			else
			{
				ThumbButton.Visible = false;
			}
			this.Height = ItemHeight * 15 + EffectHeight * 2;
			this.TopMost = true;
			this.Width = 240;
			ThumbButton.Left = this.Width - ThumbButton.Width - 2;
			ThumbButton.Top = EffectHeight;
			ThumbButton.BackgroundImageLayout = ImageLayout.Center;
			ThumbButton.BackgroundImage = DrawThumbButton();
			CaculateThumbHeight();
			DisplayHeight = this.Height - 40;
			DisplayImage = DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL);
			sAPI.DrawBP(this, DisplayImage, (byte) 255);
		}
protected override CreateParams CreateParams
		{
			get
			{
				CreateParams cp = base.CreateParams;
				cp.ExStyle = cp.ExStyle | 0x80000;
				return cp;
			}
		}
		public void frm_SettingList_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			DownEvent = true;
			MouseX = e.X;
			MouseY = e.Y;
		}
		
		public void frm_SettingList_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (DownEvent == false)
			{
				int aIndex = 0;
				aIndex = System.Convert.ToInt32((e.Y - EffectHeight) / ItemHeight);
				if (mFirstIndex + aIndex != mSelectedIndex)
				{
					mSelectedIndex = mFirstIndex + aIndex;
					sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
				}
			}
		}
		
		public void frm_SettingList_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			DownEvent = false;
		}
		private Bitmap DrawList(sAPI.ENUMMOUSEEVENT MouseEvent = sAPI.ENUMMOUSEEVENT.MOUSENORMAL)
		{
			if (this.Width <= 0 | this.Height <= 0)
			{
				return null;
			}
			try
			{
				Bitmap img = new Bitmap(this.Width - 1, this.Height - 1);
				Graphics g = Graphics.FromImage(img);
				int PageCount = 0;
				int ListCount = 0;
				PageCount = (int) ((double) (img.Height - EffectHeight * 2) / ItemHeight);
				ListCount = sItem.Count;
				g.SmoothingMode = SmoothingMode.HighQuality;
				using (Pen BorderPen = new Pen(mBorderColor, 1))
				{
					GraphicsPath BackPath = new GraphicsPath(FillMode.Alternate);
					SolidBrush BackBrush = new SolidBrush(mBackColor);
					BackPath = Skin_Class.CreateRoundPath(new Rectangle(0, 0, img.Width - 1, img.Height - 1), 3);
					g.FillPath(BackBrush, BackPath);
					g.DrawPath(BorderPen, BackPath);
					BackPath.Dispose();
					if (ListCount > PageCount)
					{
						ScrollWidth = 11;
					}
					else
					{
						ScrollWidth = 5;
					}
					if (ListCount > 0)
					{
						SolidBrush TextBrush = new SolidBrush(ItemForeColor);
						SolidBrush SelectBrush = new SolidBrush(ItemSelectForeColor);
						StringFormat StrFormat = new StringFormat();
						StrFormat.LineAlignment = StringAlignment.Center;
						StrFormat.Alignment = StringAlignment.Near;
						StrFormat.FormatFlags = StringFormatFlags.NoWrap;
						for (var i = 0; i <= PageCount; i++)
						{
							if (i + mFirstIndex < ListCount && i + mFirstIndex >= 0)
							{
								Rectangle tmpRect = new Rectangle(2, EffectHeight + i * ItemHeight, img.Width - ScrollWidth, ItemHeight);
								Rectangle TextArea = tmpRect;
								TextArea.X = (int) (TextArea.Left + 4);
								TextArea.Width = TextArea.Width - 4;
								if (mSelectedIndex == i + mFirstIndex)
								{
									LinearGradientBrush ItemBrush = new LinearGradientBrush(tmpRect, ItemSelectColor1, ItemSelectColor2, LinearGradientMode.Vertical);
									g.FillRectangle(ItemBrush, tmpRect);
									g.DrawString(System.Convert.ToString(sItem[i + mFirstIndex].Text), this.Font, SelectBrush, TextArea, StrFormat);
								}
								else
								{
									g.DrawString(System.Convert.ToString(sItem[i + mFirstIndex].Text), this.Font, TextBrush, TextArea, StrFormat);
								}
							}
							else
							{
								break;
							}
						}
						SelectBrush.Dispose();
						TextBrush.Dispose();
						StrFormat.Dispose();
					}
					if (ListCount > PageCount)
					{
						using (SolidBrush thumbBrush = new SolidBrush(thumbBackColor))
						{
							GraphicsPath ThumbBorderPath = Skin_Class.CreateRoundPath(new Rectangle(img.Width - ThumbButton.Width - 1.5, EffectHeight, ThumbButton.Width, img.Height - EffectHeight * 2 - 1), (int) ((double) (ThumbButton.Width - 1) / 2));
							g.FillPath(thumbBrush, ThumbBorderPath);
							g.DrawPath(new Pen(ThumbBorder), ThumbBorderPath);
						}
						
					}
					if (ThumbButton.BackgroundImage != null && ThumbButton.Visible == true)
					{
						g.DrawImage(ThumbButton.BackgroundImage, new Rectangle(ThumbButton.Left, ThumbButton.Top, ThumbButton.BackgroundImage.Width, ThumbButton.BackgroundImage.Height), new Rectangle(0, 0, ThumbButton.BackgroundImage.Width, ThumbButton.BackgroundImage.Height), GraphicsUnit.Pixel);
					}
				}
				
				g.Dispose();
				return img;
			}
			catch
			{
				return null;
			}
		}
		private Bitmap DrawThumbButton(sAPI.ENUMMOUSEEVENT MouseEvent = sAPI.ENUMMOUSEEVENT.MOUSENORMAL)
		{
			if (ThumbButton.Width <= 0 | ThumbButton.Height <= 0)
			{
				return null;
			}
			Bitmap Img = new Bitmap(ThumbButton.Width - 1, ThumbButton.Height - 1);
			Graphics g = Graphics.FromImage(Img);
			g.SmoothingMode = SmoothingMode.HighQuality;
			GraphicsPath gPath = new GraphicsPath(FillMode.Alternate);
			Color BarColor1 = new Color();
			Color BarColor2 = new Color();
			Color BarColor3 = new Color();
			Color BarColor4 = new Color();
			Color BarColor5 = new Color();
			Color BarBorder;
			switch (MouseEvent)
			{
				case sAPI.ENUMMOUSEEVENT.MOUSENORMAL:
					BarBorder = ThumbNormalBorder;
					BarColor1 = ThumBNormalColor1;
					BarColor2 = ThumBNormalColor2;
					BarColor3 = ThumBNormalColor3;
					BarColor4 = ThumBNormalColor4;
					BarColor5 = ThumBNormalColor5;
					break;
				case sAPI.ENUMMOUSEEVENT.MOUSEHOVER:
					BarBorder = ThumbHoverBorder;
					BarColor1 = ThumBHoverColor1;
					BarColor2 = ThumBHoverColor2;
					BarColor3 = ThumBHoverColor3;
					BarColor4 = ThumBHoverColor4;
					BarColor5 = ThumBHoverColor5;
					break;
				case sAPI.ENUMMOUSEEVENT.MOUSEDOWN:
					BarBorder = ThumbDownBorder;
					BarColor1 = ThumBDownColor1;
					BarColor2 = ThumBDownColor2;
					BarColor3 = ThumBDownColor3;
					BarColor4 = ThumBDownColor4;
					BarColor5 = ThumBDownColor5;
					break;
			}
			LinearGradientBrush Brush1 = new LinearGradientBrush(new Rectangle(0, 0, Img.Width, Img.Height), BarColor1, BarColor2, LinearGradientMode.Horizontal);
			ColorBlend ColorB = new ColorBlend();
			ColorB.Colors = new Color[] {BarColor1, BarColor2, BarColor3, BarColor4, BarColor5};
			ColorB.Positions = new Single[] {0 / 4.0F, 1 / 4.0F, 2 / 4.0F, 3 / 4.0F, 4 / 4.0F};
			gPath = Skin_Class.CreateRoundPath(new Rectangle(0, 0, Img.Width - 1, Img.Height - 1), (double) Img.Width / 2);
			Brush1.InterpolationColors = ColorB;
			g.FillPath(Brush1, gPath);
			g.DrawPath(new Pen(ThumbNormalBorder), gPath);
			Brush1.Dispose();
			gPath.Dispose();
			g.Dispose();
			return Img;
		}
		public void Remove(string Text)
		{
			int a = -1;
			for (var i = sItem.Count - 1; i >= 0; i--)
			{
				if (Text.ToLower() == sItem[System.Convert.ToInt32(i)].Text.ToLower)
				{
					sItem.RemoveAt(System.Convert.ToInt32(i));
				}
			}
			CaculateMaxValue();
			sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
		}
		public void ModifyName(string Text, string Value)
		{
			for (var i = 0; i <= sItem.Count - 1; i++)
			{
				if (Text.ToLower() == sItem[System.Convert.ToInt32(i)].Text.ToLower)
				{
					ItemStructure tmpValue = sItem[System.Convert.ToInt32(i)];
					tmpValue.Text = Value;
					sItem[System.Convert.ToInt32(i)] = tmpValue;
				}
			}
			sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
		}
		public void ThumbButton_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			OverB = false;
			ButtonDownEvent = true;
			MouseY = e.Y; //- ThumbButton.Top
			ThumbButton.BackgroundImage = DrawThumbButton(sAPI.ENUMMOUSEEVENT.MOUSEDOWN);
			sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
		}
		
		public void ThumbButton_MouseLeave(object sender, System.EventArgs e)
		{
			//DownEvent = False
			if (ButtonDownEvent == false)
			{
				OverB = false;
				ThumbButton.BackgroundImage = DrawThumbButton(sAPI.ENUMMOUSEEVENT.MOUSENORMAL);
				sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
			}
		}
		public void ThumbButton_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
			if (ButtonDownEvent == false && OverB == false)
			{
				ThumbButton.BackgroundImage = DrawThumbButton(sAPI.ENUMMOUSEEVENT.MOUSEHOVER);
			}
			sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
			if (ButtonDownEvent == true)
			{
				int SetY = ThumbButton.Top + (e.Y - MouseY);
				if (SetY >= EffectHeight & SetY <= this.Height - EffectHeight - ThumbButton.Height - 1)
				{
					ThumbButton.Top = SetY;
					Value = (double) (SetY - EffectHeight) / (this.Height - EffectHeight * 2 - ThumbButton.Height - 1);
					mFirstIndex = System.Convert.ToInt32(Value * MaxValue);
					sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
				}
			}
		}
		
		public void ThumbButton_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			ButtonDownEvent = false;
		}
		
		public void ThumbButton_Click(System.Object sender, System.EventArgs e)
		{
			
		}
		
		public void frm_SettingList_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Delta < 0)
			{
				MouseWheelData(true);
			}
			else
			{
				MouseWheelData(false);
			}
		}
		
		public void frm_SettingList_Resize(object sender, System.EventArgs e)
		{
			if (this.Width <= 0 | this.Height <= EffectHeight * 2)
			{
				return ;
			}
			ThumbButton.Left = this.Width - ThumbButton.Width - 2;
			if (sItem.Count >= 15)
			{
				this.Height = ItemHeight * 15 + EffectHeight * 2;
			}
			else if (sItem.Count > 0)
			{
				this.Height = ItemHeight * sItem.Count + EffectHeight * 2;
			}
			else if (sItem.Count <= 0)
			{
				this.Height = ItemHeight + EffectHeight * 2;
			}
			this.Width = 240;
			CaculateMaxValue();
			CaculateThumbHeight();
			sAPI.DrawBP(this, DrawList(sAPI.ENUMMOUSEEVENT.MOUSENORMAL), (byte) 255);
		}
		private void CaculateMaxValue()
		{
			int PageCount = 0;
			PageCount = (int) ((double) (this.Height - 1 - EffectHeight * 2) / ItemHeight);
			if (sItem.Count > PageCount)
			{
				ThumbButton.Visible = true;
			}
			else
			{
				ThumbButton.Visible = false;
				MaxValue = 1;
			}
			MaxValue = sItem.Count - PageCount;
		}
		private void CaculateThumbHeight()
		{
			if (MaxValue == 1)
			{
				ThumbButton.Height = this.Height - EffectHeight * 2 - 1;
			}
			else
			{
				int PageCount = 0;
				float Percent1 = 0;
				int ResultHeight = 0;
				try
				{
					PageCount = (int) ((double) (this.Height - 1 - EffectHeight * 2) / ItemHeight);
					Percent1 = (float) (((double) (this.Height - EffectHeight * 2 - 1) / ItemHeight) / (sItem.Count - PageCount) * ((double) 2 / 3)); //(sItem.Count - PageCount) / sItem.Count * (1 / 3)
					ResultHeight = (int) (Percent1 * (this.Height - EffectHeight * 2 - ThumbButton.Height - 2)); //* Math.Sqrt(1 / 3)
					if (ResultHeight < MinHeight)
					{
						ResultHeight = MinHeight;
					}
					ThumbButton.Height = ResultHeight;
				}
				catch (Exception)
				{
					ResultHeight = MinHeight;
				}
			}
		}
		private void MouseWheelData(bool PlusData = true)
		{
			//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
			if (ThumbButton.Visible)
			{
				int PageCount = 0;
				PageCount = (int) ((double) (this.Height - 1 - EffectHeight * 2) / ItemHeight);
				if (PlusData)
				{
					if (mFirstIndex + 1 < sItem.Count - PageCount + 1)
					{
						mFirstIndex++;
					}
					else
					{
						return ;
					}
				}
				else
				{
					if (mFirstIndex - 1 >= 0)
					{
						mFirstIndex--;
					}
					else
					{
						return ;
					}
				}
				ThumbButton.Top = EffectHeight + ((double) mFirstIndex / MaxValue) * (this.Height - EffectHeight * 2 - ThumbButton.Height - 2);
				sAPI.DrawBP(this, DrawList(), (byte) 255);
			}
		}
	}
}
